package com.barneyx.mshinfoplatform.web.admin.admin;

import com.barneyx.mshinfoplatform.common.ExResult;
import com.barneyx.mshinfoplatform.entity.admin.AdminRoleEntity;
import com.barneyx.mshinfoplatform.exception.AdminUserException;
import com.barneyx.mshinfoplatform.service.admin.IAdminUserEntityService;
import com.barneyx.mshinfoplatform.util.admin.AdminUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/admin/account/role/")
@Slf4j
public class AdminRoleContrller {

    @Resource
    private AdminUtil adminUtil;

    @GetMapping("roles-list")
    public ExResult<?> getRoles() {
        return ExResult.ofAuto(adminUtil.getRoles());
    }

    @GetMapping("role-by-id")
    public ExResult<?> getRoleById(@RequestParam("roleid") String roleId) {
        return ExResult.ofAuto(adminUtil.getRoleById(roleId));
    }

    /**
     * 修改分组信息
     *
     * @param roleData
     * @return
     * @throws AdminUserException
     */
    @PutMapping("update-role")
    public ExResult<?> updateRoleById(@RequestBody AdminRoleEntity roleData) throws AdminUserException {

        return ExResult.ofAuto(adminUtil.updateRoleById(roleData));
    }
    /**
     * 创建新分组
     *
     * @param roleData
     * @return
     * @throws AdminUserException
     */
    @PostMapping("create-role")
    public ExResult<?> createRole(@RequestBody AdminRoleEntity roleData) throws AdminUserException {
        return ExResult.ofAuto(adminUtil.createRole(roleData));
    }

    @DeleteMapping("delete-role-by-id")
    public ExResult<?> deleteRoleById(@RequestParam("roleid") String roleId) throws AdminUserException {
        return ExResult.ofAuto(adminUtil.deleteAdminRoleById(roleId));
    }

}
